<template>
  <el-container class="global">
    <el-aside width="200px" class="side">
      <el-menu :default-active="chenck" router class="el-menu-vertical-demo">
        <el-menu-item :index="item.path" v-for="(item, index) in list">
          <i class="el-icon-menu"></i>
          <span slot="title">{{ item.name }}</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header class="hd">
        <div>学生成绩管理系统</div>
        <div @click="logout">退出</div>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import service from "../request";
export default {
  data() {
    return {
      list: [],
      chenck: "",
    };
  },
  watch: {
    $route: {
      handler(to, from) {
        console.log(to);
        this.chenck = to.path;
      },
      immediate: true,
      // 深度观察监听
      deep: true,
    },
  },
  mounted() {
    this.getdata();
  },
  methods: {
    logout() {
      this.$router.push({
        path: "/",
      });
    },
    async getdata() {
      const res = await service.get("/menu/index", {
        params: {
          type: window.localStorage.getItem("type"),
        },
      });
      console.log(res);
      this.list = res.data;

    },
  },
};
</script>
<style>
.hd div {
  cursor: pointer;
}
.hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.is-active {
  background-color: rgba(0, 181, 249, 0.8);
  color: #fff !important;
}
.el-menu-item {
  color: #fff !important;
}
.el-menu {
  background: #444c63;
}
.side {
  background: #444c63;
}
.global {
  width: 100%;
  height: 100%;
}
.about {
  width: 100%;
  height: 100%;
}
</style>